$(function ()
{
    findMsg();
})

function findMsg()
{
    let data = fontAjax('/online', {}, 'get');

    let model = data.model;
    let productTypeList = data.productTypeList;
    let products = data.products;

    let productName = '';
    let product = '';
    let productImg = '';

    if (model != null)
    {
        $('#bigTitle').html('<a href="/html/projectServer.html">' + model.bigTitle + '</a>');
        $('#smallTitle').html(model.smallTitle);
        $('#rephone').html(model.reservationPhone);
    }

    if (productTypeList != null)
    {
        for (let i = 0; i < productTypeList.length; i++)
        {
            if (i < 5)
            {
                productName += '<div>' + productTypeList[i].productType + '</div>';
            }
        }

    }
    $('#productName').html(productName);
    if (products != null)
    {
        for (let i = 0; i < products.length; i++)
        {
            product += '<option value="' + products[i].productName + '">' + products[i].productName + '&nbsp;&nbsp;&nbsp;' + products[i].price + '元' + '</option>';
            productImg += '<img src="' + products[i].img + '" height="232" width="300"/>';
        }
    }
    $('#roomType').html(product);
    $('#productImg').html(productImg);
}

function save()
{
    let msg = {};
    msg.name = $.trim($("#name").val());
    msg.phone = $.trim($("#phone").val());
    msg.startDate = $.trim($("#startDate").val());
    msg.endDate = $.trim($("#endDate").val());
    msg.roomType = $.trim($("#roomType").val());
    msg.idea = $.trim($("#idea").val());

    let data = fontAjax('/onlineAdd', msg, 'post');

    var ifont = '';
    if (data.count == 1)
    {
        ifont += '<i class="iconfont icon-right"></i>订房成功';
        $("#ifont").html(ifont);
        $("#name").val('');
        $("#phone").val('');
        $("#startDate").val('');
        $("#endDate").val('');
        $("#idea").val('');

    }
}